Part Number Hot Search : 
N800504 MMBFJ109 10302 FRD32061 TB0448A B82498B BAS21 M50743
Product Description
Full Text Search
 

To Download AN85 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  application note 1 of 14 www.xicor.com october, 2000 AN85 interfacing the x24165/645 to the motorola 68hc11 microcontroller by applications staff this application note demonstrates how the xicor x24165/645 family of serial memories can be interfaced to the 68hc11 microcontroller family when connected as shown in fig. 1. the interface uses two general purpose port d pins to interface to the serial memories. vcc u2 68hc11a8 xt 30 ex 29 reset 39 irq 41 xirq 40 pa0 8 pa1 7 pa2 6 pe0 17 pe1 18 pe2 19 pe3 20 vrh 22 vrl 21 pa3 5 pa4 4 pa5 3 pa6 2 pa7 1 pb0 16 pb1 15 pb2 14 pb3 13 pb4 12 pb5 11 pb6 10 pb7 9 pc0 31 pc1 32 pc2 33 pc3 34 pc4 35 pc5 36 pc6 37 pc7 38 pd0 42 pd1 43 pd2 44 pd3 45 pd4 46 pd5 47 moda 25 modb 24 e 27 as 26 r/w 28 u1 x24645 nc 1 s1 2 s2 3 scl 6 wp 7 sda 5 figure 1. typical hardware connection for interfacing an x24645 to the 68hc11 microcontroller.
2 of 14 AN85 application note www.xicor.com october, 2000 ******************************************************************************* ** ** description: ** ** this file contains general utility routines written in 68hc11 assembly ** language and used to interface the m68hc11 to xicor two-wire serial memory ** family (x24xxx). the interface between the 68hc11 and x24xxx devices ** consists of a clock (scl) and a bidirectional data line (sda). the ** communication interface uses 2 pins from port d(pd3 = scl and pd2 = sda). ** other components may reside on this bus provided that they do not have the ** same device identifier byte as the serial memory. ** the following table lists all the subroutines in this file with a brief ** description: ** ** start: generate the start condition ** stop: generate the stop condition ** reset: issues the appropriate commands to force device reset ** progpage: transfer from ram buffer to serial memory page ** progbyte: transfer the contents of bytedata to the serial memory ** seqread: read multiple bytes, starting from current address pointer ** randomread: read a byte from a specific memory location ** ackpoll: return when the write cycle completes. ** outack: process the acknowledge output cycle ** getack: process the acknowledge from the slave device ** ** the main program loop programs a test string into the serial memory. after ** entire string is programmed, the content of the programmed page is read. ** the read data is stored in the internal ram. a utility program can be ** written to verify that the buffer content matches the test string. ** ******************************************************************************* ******************************************************************************* * internal ram ******************************************************************************* rambase equ $0000 the internal ram base address(default) rambuff equ rambase ram buffer address stack equ rambase+$ff ******************************************************************************* * program constants ******************************************************************************* dwom equ $20 port d wom control bit sdabit equ $04 port d bits functioning as bidirectional sclbit equ $08 serial data (sda) and serial clock (scl) pageno equ $00 page number of the serial memory bpx equ $18 bpx bits position in wpr wel equ $02 wel bit position in wpr rwel equ $04 rwel bit position in wpr wpen equ $80 wpen bit position in wpr welon equ 00000010b wel control byte rwelon equ 00000110b rwel control byte x24165 equ 0
3 of 14 AN85 application note www.xicor.com october, 2000 x24325 equ 0 x24645 equ 1 maxdelay equ $1000 number of times to check acknowledge polling bytedata equ 58h changes the x to an x in the test program seqreadsize equ 16 byte counts to shift out using seq read if x24165 deviceid equ $a0 device select and type id hiaddr equ $0f mask for upper address byte wpr_addr equ $07ff wpr physical address location (byte access) pagesize equ 32 bytes per page endif if x24325 deviceid equ $a0 device select hiaddr equ $1f mask for upper address byte wpr_addr equ $0fff wpr physical address location (byte access) pagesize equ 32 bytes per page endif if x24645 deviceid equ $80 device select hiaddrmask equ $3f mask for upper address byte wpr_addr equ $1fff wpr physical address location (byte access) pagesize equ 32 bytes per page endif ******************************************************************************* * internal registers and control block ******************************************************************************* portd equ $08 port d data register ddrd equ $09 data direction register for port d spcr equ $28 spi control register ******************************************************************************* * reset vector entry point ******************************************************************************* org $fffe reset vector address to program entry fdb $e000 jump to beginning of executable code * assembler requirement- cpu type p68h11 page ******************************************************************************* * start of user code * *******************************************************************************
4 of 14 AN85 application note www.xicor.com october, 2000 org $e000 main: lds #stack * load stack pointer * initialize the buffer before programming the content to a page ldy #rambuff * iy = ram buffer address ldx #teststring * ix = test string address initram: ldaa 0,x * copy the test string to staa 0,y * ram buffer iny inx tsta bne initram ldx #$1000 * set register base bset spcr,x,#dwom * config. port-d as open drain ldaa #$0c * pd2 = scl staa ddrd,x * pd3 = sda ldaa #$ff * configure port d staa portd,x jsr reset * reset the interface state machine ldd #wpr_addr * read the wpr content and find the jsr randomread * blocks that are locked. if both bita #wpen * wpen bit and wp pin are high then bne wpen_off * bpx bits are protected (writes are * ... warning ... * permitted when wp is brought low). * make sure that wp pin is low before attempting to write new value to * the wpr when wpen bit is set. wpen_off: bita #bpx * skip if the bpx bits are beq no_bpx * clear (no blocks are protected) clra * clear the block lock bits (unprotect jsr progbp * the entire device), wait for jsr ackpoll * write operation to complete no_bpx: jsr setwel * set the write enable bit ldd #wpr_addr * read the wpr content and jsr randomread * check that wel bit bita #wel * is set high bne writes_en * else its a failure bra * * check the device/connections*stop* writes_en: ldd #pageno * d = page number of the serial memory ldy #rambuff * iy = ram buffer address jsr progpage * transfer buffer content to the page * in serial memory indicated by d(ab) jsr ackpoll * wait till completion of page prog. jsr progbyte * write byte to serial memory jsr ackpoll * wait till completion of byte prog. jsr clrwel * reset the write enable bit ldd #pageno * d = page number of the serial memory ldy #rambuff * iy = ram buffer address
5 of 14 AN85 application note www.xicor.com october, 2000 jsr randomread * setup the address pointer and read staa 0,y * first byte, save it to the buffer iny * adjust the ram buffer pointer ldaa #.high.pageno * load the upper byte of address ldab #$20 * specify byte count for seq. read op jsr seqread * read/store the remaining data bra * * end of main page ******************************************************************************* *** name: seqread *** description: read sequentially from the serial memory *** function: this subroutine extracts contents of the serial memory and stores *** them into the specified ram buffer. the total number of bytes to *** read should be provided along with the buffer address. this *** routine assumes that the address pointer has already been *** initialized using the inbyte routine. *** calls: start, slavaddr, inbyte, outack, stopread *** input: iy = ram buffer base address, a = high order address *** b = number of bytes to read *** output: none *** register usage: a, b, iy ******************************************************************************* seqread: jsr start * start sec * [c=1] read operation bit jsr slavaddr * send the slave address byte seqreadnxt: jsr inbyte * start reading from the current address staa 0,y * total number of bytes to read out of iny * serial memory decb * beq seqreadend * jsr outack * send an acknowledge to the device bra seqreadnxt seqreadend: jmp stopread * end of read operation ******************************************************************************* *** name: randomread *** description: reads content of the serial memory at a specific location. *** function: this subroutine sends out the command to read the content of a *** memory location specified in the (d) register. *** calls: start, inbyte, slavaddr, outbyte, stopread *** input: d = address of the byte *** output: a = read value *** register usage: a ******************************************************************************* randomread: psha jsr start * start clc * [c=0] write operation bit jsr slavaddr * send the slave address byte tba * load the lower byte of the page jsr outbyte * address and shift out to the device
6 of 14 AN85 application note www.xicor.com october, 2000 pula * recall high address byte jsr start * start sec * [c=1] read operation bit jsr slavaddr * send the slave address byte jsr inbyte * shift in a byte from the device jmp stopread * end operation ******************************************************************************* *** name: stopread *** description: terminate read operation *** function: this subroutine is called at the end of a read operation. the *** routine generates the last ack clock cycle followed by a stop *** command. the last ack bit clock cycle differs from the normal *** ack bit in that the sda line is held high. this action notifies *** the serial memory that it should suspend operation. *** calls: clockpulse, stop *** input: none *** output: none *** register usage: none ******************************************************************************* stopread: bset portd,x,#sdabit * make sure that the data line is high ... bset ddrd,x,#sdabit * change the pdx direction to output jsr clockpulse * jmp stop * end operation page ******************************************************************************* *** name: progpage *** description: update a page of the serial memory *** function: this subroutine transfers the contents of the given buffer to the *** serial memory. the caller program must supply the page *** number of the serial memory to update and the base address *** of the ram buffer. *** calls: start, slavaddr, outbyte, stop *** input: iy = ram buffer base address, d(ab) = page number *** output: none *** register usage: a,b ******************************************************************************* progpage: jsr start * start clc * [c=0] write operation bit jsr slavaddr * send the slave address byte tba * load the lower byte of the page address anda #$0e0 * mask out the unwanted lower bits jsr outbyte * and shift out to the device ldab #pagesize * transfer content of the ram buffer progpagenxt: ldaa 0,y * to the serial memory jsr outbyte * iy should be pointing to the buffer ldaa #$0ff * cover up your tracks as buffer is staa 0,y * read and stored to the serial memory iny * total number of bytes transfered decb * to the serial memory should not exceed
7 of 14 AN85 application note www.xicor.com october, 2000 bne progpagenxt * the page size jmp stop * end of the operation ******************************************************************************* *** name: progbyte *** description: write a byte to serial memory *** function: this subroutine transfers the contents of bytedata to the *** serial memory. the address written to is conained in the *** slave address and the byte address d(ab). *** calls: start, slavaddr, outbyte, stop *** input: d(ab) = byte address *** output: none *** register usage: a,b ******************************************************************************* progbyte: jsr start * start clc * [c=0] write operation bit jsr slavaddr * send the slave address byte tba * load the lower byte of the page address anda #$0e0 * mask out the unwanted lower bits jsr outbyte * and shift out to the device ldaa #bytedata * load the data to be written jsr outbyte * send out data to the serial memory jmp stop * ******************************************************************************* *** name: enprogwpr *** description: enable updates to write protect register (wpr) *** function: this subroutine writes the appropriate sequence to the serial memory *** to enable updating of the wpr. the progwpen and progbp routines *** must call this subroutine before writes to the wpr are allowed. *** once this sequence is activated, the only way to exit this mode *** is by writing to the wpr or resetting the serial memory. *** calls: randomread, setwel, setrwel *** input: none *** output: a = initial wpr value *** register usage: a, b ******************************************************************************* enprogwpr: ldd #wpr_addr * read the wpr content and jsr randomread * test the status of bita #wel * the wel bit and bne progwpr_1 * skip if its set psha * all writes to the wpr are disallowed jsr setwel * when the wel is clear, send set wel pula * command progwpr_1: bita #rwel * check the rwel bit and bne progwpr_2 * skip if its set psha * writing to block-lock bits or wpen jsr setrwel * bit require that rwel to be set, pula * send set rwel command progwpr_2: rts
8 of 14 AN85 application note www.xicor.com october, 2000 page ******************************************************************************* *** name: progbp *** description: update block lock bits in wpr of the serial memory *** function: this subroutine writes to the wpr of the serial memory and *** changes the bp1:0. the caller program must supply the new values *** for the bp1:0 bits. this routine retains the original state of *** the wpen bit. *** calls: addrwpr, enprogwpr, outbyte, stop *** input: a[1:0] = bp[1:0] *** output: none *** register usage: a, iy ******************************************************************************* progbp: anda #$03 * mask out the unwanted bits asla * shift the bpx bits to the asla * bit positions 4:3 asla psha * save the bpx new values and jsr enprogwpr * enable writing to the wpr anda #$9a * create the data pattern by masking oraa #$02 * in the desired bit pattern and tsy * saving status of wpen bit oraa 0,y * set the bpx bits per requested pattern staa 0,y * save the wpr value onto the stack jsr addrwpr * generate wpr write command pula * shift out wpr pattern jsr outbyte * to the device jmp stop ******************************************************************************* *** name: progwpen *** description: update write protect enable bit in wpr of the serial memory *** function: this subroutine writes to the wpr of the serial memory and *** changes the wpen bit. the caller program must supply the new *** value of the wpen bit. the state of the bp1:0 bits are preserved. *** calls: addrwpr, enprogwpr, outbyte, stop *** input: c *** output: none *** register usage: a, iy ******************************************************************************* progwpen: clra * load the status flags rora * mask out the unwanted bits psha * save the wpen bit new value and jsr enprogwpr * enable writing to the wpr anda #$9a * create the data pattern by masking oraa #$02 * in the desired bit pattern and tsy * saving status of wpen bit oraa 0,y * set the wpen bit per as requested staa 0,y * save the wpr value onto the stack jsr addrwpr * generate wpr write command
9 of 14 AN85 application note www.xicor.com october, 2000 pula * shift out wpr pattern jsr outbyte * to the device jmp stop ******************************************************************************* *** name: setwel *** description: set the write enable latch (wel) bit in the wpr of the serial memory. *** function: this subroutine writes to the wpr of the serial memory and *** sets the wel bit. *** calls: addrwpr, outbyte, stop *** input: none *** output: none *** register usage: a ******************************************************************************* setwel: jsr addrwpr * generate wpr write command ldaa #welon * shift out wel-on pattern jsr outbyte * to the device jmp stop ******************************************************************************* *** name: clrwel *** description: reset the write enable latch (wel) bit in the wpr of the serial memory. *** function: this subroutine writes to the wpr of the serial memory and *** resets the wel bit. *** calls: addrwpr, outbyte, stop *** input: none *** output: none *** register usage: a ******************************************************************************* clrwel: jsr addrwpr * generate wpr write command clra * shift out wel-off pattern jsr outbyte * to the device jmp stop ******************************************************************************* *** name: setrwel *** description: set register write enable latch bit in the wpr of the serial memory. *** function: this subroutine writes to the wpr of the serial memory and *** sets the rwel bit. *** calls: addrwpr, outbyte, stop *** input: none *** output: none *** register usage: a ******************************************************************************* setrwel: jsr addrwpr * generate wpr write command ldaa #rwelon * shift out rwel-on pattern jsr outbyte * to the device jmp stop page
10 of 14 AN85 application note www.xicor.com october, 2000 ******************************************************************************* *** name: addrwpr *** description: initiate write operation to the wpr of the serial memory. *** function: this subroutine issues the wpr address and write instruction *** to the serial memory. *** calls: start, slavaddr, outbyte *** input: none *** output: none *** register usage: a,b ******************************************************************************* addrwpr: ldd #wpr_addr jsr start * start [ c = operation bit ] clc * [c=0] write operation bit jsr slavaddr * send the slave address byte tba * load the lower byte of address jmp outbyte * and shift out to the device ******************************************************************************* *** name: slavaddr *** description: build the slave address for the serial memory. *** function: this subroutine concatenates the bit fields for device id, *** the high address bits and the command bit. the resultant *** byte is then transmitted to the serial memory. *** calls: outbyte *** input: d(ab) = page number *** c = command bit (=0 write, =1 read) *** output: none *** register usage: a ******************************************************************************* slavaddr: rola * merge the command bit eora #deviceid * and the device select bits anda #hiaddrmask * with the upper byte of eora #deviceid * page address jmp outbyte * send the slave address ******************************************************************************* *** name: outbyte *** description: sends a byte to the serial memory *** function: this subroutine shifts out a byte, msb first, through the *** assigned sda/scl lines on port d. *** calls: clockpulse, getack *** input: a = byte to be sent *** return value: none *** register usage: a ******************************************************************************* outbyte: bset ddrd,x,#sdabit * change the pdx direction to output sec outbytenxt: rola * shift out the byte, msb first bcc outbyte0 bset portd,x,#sdabit bra outbyte1
11 of 14 AN85 application note www.xicor.com october, 2000 outbyte0: bclr portd,x,#sdabit outbyte1: jsr clockpulse * clock the data into the serial memory cmpa #10000000b * memory clc * loop if all the bits have bne outbytenxt * not been shifted out jmp getack * check for an ack from the device page ******************************************************************************* *** name: inbyte *** description: shifts in a byte from the serial memory *** function: this subroutine shifts in a byte, msb first, through the *** assigned sda/scl lines on port d. after the byte is received *** this subroutine does not send out an ack bit to the serial memory. *** calls: clockpulse *** input: none *** return value: a = received byte *** register usage: a ******************************************************************************* inbyte: ldaa #00000001b bclr ddrd,x,#sdabit * change the pdx direction to input inbytenxt: jsr clockpulse * clock the serial memory and shift rola * into acc. the logic level on the sda bcc inbytenxt * line. the device outputs data on sda, rts * msb first ******************************************************************************* *** name: clockpulse *** description: generate a clock pulse *** function: this subroutine forces a high-low transition on the *** assigned scl line on port d. it also samples the sda *** line state during high clock period. *** calls: none *** input: none *** return value: c = sda line status *** register usage: none ******************************************************************************* clockpulse: bset portd,x,#sclbit * force scl line high. based nop * on an 8mhz crystal freq. the system nop clc * bus cycle time is 0.5 microsec. brclr portd,x,#sdabit,clockpulselo * sec clockpulselo: bclr portd,x,#sclbit * lower the clock line rts *******************************************************************************
12 of 14 AN85 application note www.xicor.com october, 2000 *** name: outack *** description: send out an ack bit to the serial memory *** function: this subroutine changes the direction of the sda pin on port d *** and then clocks an ack bit to the serial memory. the ack *** cycle acknowledges a properly received data by lowering the *** sda line during this period (9th clock cycle of a received *** byte). the direction of the sda pin is programmed as input *** prior to returning to the caller. *** calls: clockpulse *** input: none *** return value: none *** register usage: none ******************************************************************************* outack: bclr portd,x,#sdabit * make sure that the data line is low ... bset ddrd,x,#sdabit * change the pdx direction to output jmp clockpulse * ******************************************************************************* *** name: getack *** description: clock the serial memory for an ack cycle *** function: this subroutine changes the direction of the sda pin on port d *** and then clocks the serial memory. it returnes the sampled *** logic level on the sda during high clock cycle. the serial memory *** acknowledges a properly received command/data by lowering the *** sda line during this period (9th clock cycle of a transmitted *** byte). if the sda state is high, it signifies that either it *** did not receive the correct number of clocks or it's stuck in *** previously initiated write command, *** calls: clockpulse *** input: none *** return value: c = acknowledge bit *** register usage: none ******************************************************************************* getack: bclr ddrd,x,#sdabit * change the pdx direction to input jsr clockpulse * clock the serial memory bset ddrd,x,#sdabit * change the pdx direction to output rts page ******************************************************************************* *** name: ackpoll *** description: wait for an ack from the serial memory *** function: this subroutine sends a slave address to the serial memory and *** monitors the sda for an ack signal. it returns if a low *** logic level is detected on the sda during high clock cycle of *** the acknowledge cycle. the serial memory does not respond to any *** commands with an acknowledge bit while the store operation *** is in progress. if no ack is received another slave address is *** sent to the serial memory. the number of iteration is specified *** by the maxdelay constant. *** calls: start, slavaddr, stop *** input: none
13 of 14 AN85 application note www.xicor.com october, 2000 *** return value: c = acknowledge bit [=0 ack ,=1 no ack was received] *** register usage: a, b, iy ******************************************************************************* ackpoll: ldy #maxdelay * load max no. of ack polling cycle ackpollnxt: jsr start * start the ack poll cycle and ldd #pageno * d = page number of the serial memory clc * [c=0] write operation bit jsr slavaddr * send the slave address. then * * monitor the sda line for an ack from * * the serial memory. terminate the jsr stop * operation by a stop condition. bcc ackpollexit * exit if the ack was received dey bne ackpollnxt * loop while the maximum no. of cycles * * have not expired. else return with c=1 ackpollexit: rts ******************************************************************************* *** name: start *** description: send a start command to the serial memory *** function: this subroutine generates a start condition on the bus. the start *** condition is defined as a high-low transition on the sda *** line while the scl is high. the start is used at the beginning *** of all transactions. *** calls: none *** input: none *** return value: none *** register usage: none ******************************************************************************* start: bset portd,x,#sdabit * force the sda line high bset portd,x,#sclbit * force the scl clock line high bclr portd,x,#sdabit * before taking the sda low nop nop nop nop bclr portd,x,#sclbit * force the scl low rts ******************************************************************************* *** name: stop *** description: send stop command to the serial memory *** function: this subroutine generates a stop condition on the bus. the stop *** condition is defined as a low-high transition on the sda *** line while the scl is high. the stop is used to indicate end *** of current transaction. *** calls: none *** input: none *** return value: none *** register usage: none *******************************************************************************
14 of 14 AN85 application note www.xicor.com october, 2000 stop: bclr portd,x,#sdabit * force the sda low before taking bset portd,x,#sclbit * the scl clock line high nop nop nop nop bset portd,x,#sdabit * force the sda high (idle state) rts ******************************************************************************* *** name: reset *** description: resets the serial memory *** function: this subroutine is written for the worst case. system interruptions *** caused by brownout or soft error conditions that reset the main *** cpu may have no effect on the internal vcc sensor and reset *** circuit of the serial memory. these are unpredictable and *** random events that may leave the serial memory interface *** logic in an unknown state. issuing a stop command may not be *** sufficient to reset the serial memory. *** calls: start, stop *** input: none *** return value: none *** register usage: b ******************************************************************************* reset: ldab #$0a * apply 10 clocks to the device. each resetnxt: jsr start * cycle consists of a start/stop jsr stop * this will terminate pending write decb * command and provides enough clocks bne resetnxt * for unshifted bits of a read rts * operation teststring: fcc 'xicor makes it memorable!' fcb $00 ******************************************************************************* *** end of x24xxx serial memory interterface source code ******************************************************************************* end


▲Up To Search▲   

 
Price & Availability of AN85

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X